const route_dataManaTag = 'route_dataMana';

const cla_route_dataMana_prop_route_data = 'route_data';

const path_split = '/';

class route_dataMana {
  get [Symbol.toStringTag]() {
    return route_dataManaTag;
  }

  constructor(root_path) {
    this.root_path = root_path;
  }

  /**
   * 根 节点
   * @type {string}
   */
  root_path;

  /**
   * 路由 堆栈
   */
  [cla_route_dataMana_prop_route_data] = [];

  /**
   * 跳转 到 路由
   * @param {string} path
   */
  go(path) {
    this[cla_route_dataMana_prop_route_data].push(path);

    this.#set_path(this.#get_total_path(path));
  }

  /**
   * 回退 到 之前的 路由
   * @param {number} num
   */
  back(num = -1) {
    let path;
    let index = this.route_data.length - 1;

    for (; num < -1; ) {
      num++;
      index--;
    }

    path = this.route_data[index];

    this.#set_path(this.#get_total_path(path));
  }

  /**
   * 跳转 路由
   * @param {string} total_path
   */
  #set_path(total_path) {
    window.location.href = total_path;
  }

  /**
   * 获取 完整的 path 信息
   * @param {string} path
   * @returns
   */
  #get_total_path(path) {
    return this.root_path + path_split + path;
  }
}

export { route_dataMana };
